import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:heven/widget/button.dart';

class UserWidget extends StatefulWidget {
  const UserWidget({super.key, this.userName = '', this.isTourist = 1});
  final String? userName;
  final int? isTourist;
  @override
  State<UserWidget> createState() => _UserWidgetState();
}

class _UserWidgetState extends State<UserWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.centerLeft,
      margin: const EdgeInsets.fromLTRB(10, 0, 26, 10),
      padding: const EdgeInsets.all(7),
      child: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              margin: const EdgeInsets.only(right: 18),
              height: 55,
              width: 55,
              child: Image.asset(
                widget.isTourist != 0
                    ? 'assets/images/avatar_not_login.png'
                    : 'assets/images/avatar_login.png',
                height: 55,
                width: 55,
              ),
            ),
            Expanded(
              flex: 1,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    widget.userName ?? '',
                    maxLines: 1,
                    softWrap: true,
                    overflow: TextOverflow.ellipsis,
                    style: const TextStyle(
                      color: Color(0xFFFFFFFF),
                      fontSize: 13,
                      height: 1.4,
                    ),
                  ),
                  Expanded(
                    // 填充剩余空间
                    flex: 1,
                    child: Container(), // 可以是空的，用于占位
                  ),
                  Offstage(
                    offstage: widget.isTourist == 0,
                    child: ButtonWidget(
                      width: 70,
                      height: 21,
                      margin: const EdgeInsets.all(0),
                      child: const Text(
                        '登录/注册 ',
                        style: TextStyle(
                            fontSize: 11,
                            color: Color(0xFF000000),
                            fontWeight: FontWeight.bold),
                      ),
                      onTap: () {
                        Navigator.pushNamed(context, '/login/list');
                      },
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
